package models

import "gorm.io/gorm"

type Goods struct {
	gorm.Model
	Title  string  `gorm:"type:varchar(30);not null;comment:商品标题"`
	Price  float64 `gorm:"type:decimal(10,2);not null;comment:商品单价"`
	Stock  int     `gorm:"type:int(11);not null;comment:商品库存"`
	Status int     `gorm:"type:tinyint;not null;comment:商品状态 0:审核中 1:上架中 2:下架"`
}

func (g *Goods) AddGoods() error {
	return DB.Debug().Create(&g).Error
}

func (g *Goods) FindGoods() (goods []*Goods, err error) {
	err = DB.Debug().Find(&goods).Error
	return
}

func (g *Goods) ShowGoods() error {
	return DB.Debug().Where("id = ?", g.ID).Find(&g).Error
}
